<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="app">
        firstName:<input type="text" placeholder="请输入名" v-model="firstName">
        lastName:<input type="text" placeholder="请输入姓" v-model="lastName">
        fullName:<input type="text" placeholder="请输入姓" v-model="fullName">
        {{test}}
    </div>
</body>
<script src="./js/vue.js"></script>
<script>
    Vue.config.productionTip = false;

    new Vue({
        el:"#app",
        data:{
            firstName:"T",
            lastName:"Mac",
            test:"test"
        },
        methods:{
            //methods中的函数一般是结合v-on一起使用的
            //methods中的函数一般都是事件对应的回调函数
            /*fullName(){
                console.log("fullName")
                return `${this.firstName}-${this.lastName}`
            }*/
        },
        mounted(){
            setTimeout(()=>{this.test="test2"},2000)
        },
        computed:{
            fullName:{
                get(){
                    console.log("get")
                    return `${this.firstName}-${this.lastName}`
                },
                set(newVal){
                    //newVal : 用户实时输入的值
                    var arr = newVal.split("-");
                    this.firstName = arr[0];
                    this.lastName = arr[1];
                }
            }
        }
    })
</script>
</html>